package me.leiusual.sharing.ui.useraccount

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.map
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import androidx.paging.PagedList
import me.leiusual.sharing.api.model.UserAccountLog
import me.leiusual.sharing.repository.UserAccountRepository
import me.leiusual.sharing.repository.model.Data
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountDetailViewModel @Inject constructor(
    private val userAccountRepository: UserAccountRepository
) : ViewModel() {

  // 账户详情

  private val _userAccountDetail = MutableLiveData<Long>()
  private val _listing = map(_userAccountDetail) {
    userAccountRepository.userAccountDetail(it)
  }
  val loadInitial: LiveData<Data<Unit>> = switchMap(_listing) {
    it.loadInitial
  }
  val pagedList: LiveData<PagedList<UserAccountLog>> = switchMap(_listing) {
    it.pagedList
  }

  fun userAccountDetail(id: Long) {
    _userAccountDetail.value = id
  }
}